import java.nio.charset.Charset;
import java.util.Date;
import java.util.Formatter;
import java.util.Map;


public class CharsetTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
	    
        Map<String,Charset > listCharset = Charset.availableCharsets();
        
        for (String key:listCharset.keySet()) {
            System.out.println(key + ":" + listCharset.get(key).displayName());
        }
	    
        String defaultCharsetName=Charset.defaultCharset().displayName();   

        System.out.println("defaultCharsetName:"+defaultCharsetName);  
		String str = "中国人";
		log("utf-8:" + str);
		logBytes(str.getBytes());
		log("utf-16:" + str);
		logBytes(str.getBytes(Charset.forName("utf-16")));
		
		
		
	}
	
	private static void log(String msg) {
		System.out.println(msg);
	}
	
	private static void logBytes(byte[] array) {
		System.out.print(" byte[]:");
		for (byte b : array) {
			
			Formatter str = new Formatter().format("0x%x ", b);
			System.out.print(str.toString());
		}
		System.out.println("\n\r");
	}
}
